<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title></title>
  
    <link href="../static/mui/css/mui.min.css" rel="stylesheet"/>
    <link href="../static/mui/css/iconfont.css" rel="stylesheet"/>
    <style>
    	.mui-bar-tab .mui-tab-item.mui-active{color:#dd524d;}
    </style>
</head>
<body>
    <nav class="mui-bar mui-bar-tab" style="background: #F7F7F7;">
        <a id="defaultTab" class="mui-tab-item mui-active" href="order/indexList.html">
            <span class="mui-icon iconfont icon-icon"></span>
            <span class="mui-tab-label">接单</span>
        </a>
        <a class="mui-tab-item" href="order/manage.html">
            <span class="mui-icon iconfont icon-dingdan"></span>
            <span class="mui-tab-label">订单管理</span>
        </a>
        <a class="mui-tab-item" href="my/index.html">
            <span class="mui-icon iconfont icon-wode"></span>
            <span class="mui-tab-label">我的</span>
        </a>
        <a class="mui-tab-item" href="help.html">
            <span class="mui-icon iconfont icon-gengduo"></span>
            <span class="mui-tab-label">更多</span>
        </a>
    </nav>
	<script type="text/javascript" src="../static/lib/jquery-1.11.2.min.js"></script>
	<script src="../static/mui/js/mui.min.js"></script>
	<script type="text/javascript" src="../static/app/js/prop.js"></script>
	<script type="text/javascript" src="../static/app/js/kit.js"></script>
	<script type="text/javascript" src="../static/app/js/api.js"></script>
    <script type="text/javascript">
    	mui.plusReady(function(){
    		/**
    		 * 注册事件 可以在其他页面调用 进行页面的预加载
    		 */
             var indexList="";
             var manage="";
             var index="";
             var help="";
    		window.addEventListener("indexwebview",function(event){
    			var subpages = ['order/indexList.html', 'order/manage.html', 'my/index.html', 'help.html'], subpageStyle = {top: '0px',bottom: '50px'};
       			var self,activeTab;
	    		//获取当前页面webview
	            self = plus.webview.currentWebview();
	            //隐藏当前webview的滚动条
				self.setStyle({scrollIndicator: 'none'});
	            //在当前的webview中生成下方四个tab选项卡所对应的子页面
	            for (var i = 0; i < subpages.length; i++) {
	                //创建多个子的页面webview对象
	                var sub = plus.webview.create(subpages[i], subpages[i], subpageStyle);
	                if (i > 0) {
	                    sub.hide();
	                    activeTab = subpages[0];
	                }
	                self.append(sub);
	            }
	             //绑定下方四个tab选项卡点击事件
	            $('.mui-tab-item').on('tap', function(){ 
	            	var shop = Kit.dao.get("SHOP",true);
	                var targetTab = $(this).attr('href');
	                if (targetTab == activeTab) {
	                	//如果点击的是当前页面选项卡，则不处理
	                    return;
	                } else {
	                    //显示目标选项卡
	                    if(targetTab=='order/indexList.html'){
	                    	if(!indexList){
	            		      indexList= plus.webview.getWebviewById(targetTab); 
	            		      mui.fire(indexList,"getOrderIndexData",{shopid:shop.ID});
	            		    }
	            		}
	                    else if(targetTab=='order/manage.html'){
	                    	if(!manage){
	            		       manage= plus.webview.getWebviewById(targetTab); 
	            		       mui.fire(manage,"getManageData",{shopid:shop.ID});
	            		    }
	            		}
	                    else if(targetTab=='my/index.html'){
							if(!index){
	            		    	index= plus.webview.getWebviewById(targetTab); 
	            		    	mui.fire(index,"getMyIndexData",{shop:shop});
							}
	            		}
	                    else if(targetTab=='help.html'){
	                    	if(!help){
	            		    	help= plus.webview.getWebviewById(targetTab); 
	                    	}
	            		}
	                    plus.webview.show(targetTab, "auto");
	                    //隐藏当前
	                    plus.webview.hide(activeTab);
	                    //记录当前活跃的选项卡
	                    activeTab = targetTab;
	                }
	            }); 
          });
        	var backButtonPress = 0;
			mui.back = function(event) {
				backButtonPress++;
				if (backButtonPress > 1) {
					//获取应用主Activity实例对象 Android平台完整Java类名为android.app.Activity，
					 var main = plus.android.runtimeMainActivity();
					 //切换到后台
    				 main.moveTaskToBack(false);
					//plus.runtime.quit();
				} else {
					Kit.ui.alert('再按一次退出应用');
				}
				setTimeout(function() {
					backButtonPress = 0;
				}, 1000);
				return false;
			};
    	});
    </script> 
</body>
</html>